from rest_framework import serializers
from ctbloge.apps.accounts.models import UserProfile
from .models import SiteInfo, FriendLink, Carousel,Announcement, Menu, OauthConfig


class SiteInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = SiteInfo
        fields = '__all__'
class BlogHeaderInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = SiteInfo
        fields = ['id', 'name', 'title', 'logo']
class UserInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserProfile
        fields = ['nickname','avatar','bio']
    def get_avatar_url(self, obj):
        request = self.context.get('request')
        return obj.get_avatar_url(request)
class UserfooterInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserProfile
        fields = ['id','email','wechat_qrcode','wechat_gzh_qrcode']
class AboutSiteInfoSerializer(serializers.ModelSerializer):
    bloguser = UserInfoSerializer()
    class Meta:
        model = SiteInfo
        fields = ['id', 'name', 'title', 'description', 'bloguser']
class BlogfooterInfoSerializer(serializers.ModelSerializer):
    bloguser = UserfooterInfoSerializer()
    class Meta:
        model = SiteInfo
        fields = ['id', 'name','bloguser','icp','public_record','copyright']
class ArticleDetailInfoSerializer(serializers.ModelSerializer):
    class Meta:
        model = SiteInfo
        fields = ['is_reward','alipay_reward_qrcode', 'wechat_reward_qrcode']
class BackgroundImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = SiteInfo
        fields = ['background']
class OauthConfigSerializer(serializers.ModelSerializer):
    class Meta:
        model = OauthConfig
        fields = ['id', 'name', 'is_enable']
class SiteAuthSerializer(serializers.ModelSerializer):
    oauth_list = OauthConfigSerializer(many=True)
    class Meta:
        model = SiteInfo
        fields = ['is_oauth', 'oauth_list']

class FriendLinkSerializer(serializers.ModelSerializer):
    class Meta:
        model = FriendLink
        fields = '__all__'

class CarouselSerializer(serializers.ModelSerializer):
    created_date = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)
    modified_date = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)
    class Meta:
        model = Carousel
        fields = '__all__'


class AnnouncementSerializer(serializers.ModelSerializer):

    class Meta:
        model = Announcement
        fields = '__all__'
class MenuSerializer(serializers.ModelSerializer):

    class Meta:
        model = Menu
        fields = '__all__'
